﻿///<reference path="../assets/js/jquery/jquery.js"/>

/*---------------------------------------------------------------------------
											Common functions used by our widget framework
											Author:Levin Van
											Revision:080808
											Dependence:jquery.js(1.2.x)
----------------------------------------------------------------------------*/
function initAZone(zone) {
	zone.children("div.clear").remove();
	$("div.endwithclearboth", zone).after('<div class="clear"></div>');
}

function _initZones(){
	$("div.widgetzone").each(
		function(i){
			initAZone($(this));
		}
	);
}
//Effects array,used to generate a random effect.Used with "show/hide/toggle"
var UIEffects = function() {
	//private
	var _getDirection = function(name) {
		var dir = {};
		var dir1 = ["horizontal", "vertical"];
		var dir2 = ["left", "right", "up", "down"];
		switch (name) {
			case "clip":
				dir.direction = dir1[Math.floor(Math.random() * 2)];
				break;
			case "blind":
				dir.direction = dir1[Math.floor(Math.random() * 2)];
				break;
			case "drop":
				dir.direction = dir2[Math.floor(Math.random() * 4)];
				break;
			case "explode":
				break;
			case "fold":
				break;
			case "puff":
				break;
			case "slide":
				dir.direction = dir2[Math.floor(Math.random() * 4)];
				break;
			default:
				break;
		}
		return dir;
	}; //endof _getDirection
	var _myeffects = [
		{ name: "clip", dir: _getDirection("clip") },
		{ name: "blind", dir: _getDirection("blind") },
		{ name: "drop", dir: _getDirection("drop") },
		{ name: "slide", dir: _getDirection("slide") },
		{ name: "explode", dir: {} },
		{ name: "fold", dir: {} },
		{ name: "puff", dir: {} }
	];
	var resolveEffects = function(effectsNameArray) {
		if (effectsNameArray == null || effectsNameArray.length == 0) return _myeffects;
		var retEffects = []; //return effects
		$(_myeffects).each(function(i) {
			if ($.inArray(this.name, effectsNameArray) > -1) {
				retEffects.push(this);
			}
		});
		return retEffects;
	}; //endof resolveEffects

	//public
	return {
		random: function(opts) {
			var effects = opts.effects; //["fold","slide"]
			effects = resolveEffects(effects);
			return effects[Math.floor(Math.random() * effects.length)];
		}
	};
} ();

$(document).ready(_initZones);